package com.cloud.code.算法.动态数组;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Test {

    public static void main(String[] args) {

        Array<Integer> array = new Array<>(3);
        List<Integer> arrayList = new ArrayList<>(3);
        long l = System.currentTimeMillis();
        for (int i = 0; i < 20000000; i++) {
            arrayList.add(i,i);
        }


//        array.removeFast();
        System.out.println(System.currentTimeMillis() - l);
    }


    private static void sort(int[] A, int l, int r) {

        // stack overflow
        if(r - l <= 1) {
            return;
        }

        int mid = (l+r+1)/2;
        sort(A, l, mid);
        sort(A, mid, r);

        merge(A, l, mid, r);
    }

    private static void merge(int[] A, int l, int mid, int r) {
        int[] B = Arrays.copyOfRange(A, l, mid+1);
        int[] C = Arrays.copyOfRange(A, mid, r+1);


        B[B.length-1] = C[C.length - 1] = Integer.MAX_VALUE;

        int i = 0, j = 0;

        for(int k = l; k < r; k++) {
            if(B[i] < C[j]) {
                A[k] = B[i++];
            } else {
                A[k] = C[j++];
            }
        }

    }
}
